const express = require("express");

const router = express.Router();
const { NoticeModel, user } = require("../models/model");

router.get("/notice", async (req, res) => {
  let page = 1;
  let pagesize = 3;
  let data = await NoticeModel.find().sort({ time: -1 });
  res.send({
    code: 200,
    result: data,
  });
});
router.post("/addFriend", async (req, res) => {
  const { userId, friendId } = req.body;
  try {
    await user.findByIdAndUpdate(userId, {
      $addToSet: { friends: friendId }, // 使用 $addToSet 防止重复添加
    });
    res.send({ message: "好友添加成功" });
  } catch (error) {
    res.send({ message: "添加好友失败", error: error.message });
  }
});
module.exports = router;
